How Do I Create a Custom Function for the .NET Report Engine?
The .NET Report Engine (the Engine) ships with many functions, however, you may find from time to time you require a function customized to your needs that does not exist in our library. The Engine allows you to define your own custom macro functions to expand the Fluent reporting functionality.
In this article we'll work step by step through a Catapult .NET Report Engine custom function example. We'll create a function "LOG(n)", which returns the common logarithm of its argument n.
Requirements
All that's required is the .NET Report Engine.
Create the Custom Function
Navigate to: https://github.com/windward-studios/Windward-Samples and download the code samples as a zip.
Once the zip is downloaded, extract the zip. Then, under C# Samples > Specialized, there will be a project called CustomFunctions. Open that folder and open the WindwardCustomFunctions.sln with Visual Studio.
In the Visual Studio Solution Explorer, select the file WindwardCustomFunctions.cs.
Paste this code after the last class MULTIPLYALL:
[FunctionDescription("Returns the common logarithm of the inputted parameter")]
public static double LOG(
[ParameterDescription("Take the common logarithm of this inputted number")] double num)
//Note the use of [ParameterDescription(string)] which allows for custom tip information in AutoTag.
{
return System.Math.Log10(num); //Returns the logarithm of the parameter.
}
Finally, click on Build, then select Rebuild Solution.
A notification in the Output pane indicates the build was successful. The build produced a DLL called WindwardCustomFunctions.dll.
To find the new WindwardCustomFunctions.dll file, in Solution Explorer right-click on the project, then select Open Folder in File Explorer.
In File Explorer navigate to WindwardCustomFunctions\bin\Debug\, and there is your new WindwardCustomFunctions.dll. Note this location for the custom function installation steps below.
Install the Custom Function
Installing this new custom function depends on an option you chose during the .NET Report Engine installation. If you chose to install your DLLs into the Global Assembly Cache (GAC) – the installation default – you must register your new DLL in the Global Assembly Cache. If you did not chose this option, you must copy your new DLL to the .NET Report Engine and Report Designer installation directories. Choose the option that applies to you below, and follow those instructions.
.NET Report Engine DLLs Were Installed Into the GAC
- Open a Visual Studio Command Prompt as administrator (Right-click on Start -> Visual Studio 2015 -> Developer Command Prompt for VS2015 and select "Run as administrator". This will vary depending on your Visual Studio version.).
- Navigate to the directory where your WindwardCustomFunctions.dll file is located (as shown above): “cd C:\Users\%USERNAME%\Documents\Windward DotNet Engine Samples\CS\Specialized\CustomFunctions\WindwardCustomFunctions\bin\Debug"
- Add your new WindwardCustomFunctions.dll file to the GAC by typing: “gacutil /i WindwardCustomFunctions.dll”
.NET Report Engine DLLs Were NOT Installed into the GAC
- In File Explorer navigate to the directory where your WindwardCustomFunctions.dll file is located (as shown above): "C:\Users\%USERNAME%\Documents\Windward DotNet Engine Samples\CS\Specialized\CustomFunctions\WindwardCustomFunctions\bin\Debug."
- Copy the file WindwardCustomFunctions.dll.
- Navigate to the install directory of the .NET Engine (wherever yhou extracted your zip file)
- Open the directory dll\.
- Delete the current WindwardCustomFunctions.dll file.
- Paste your new file in its place.
- Also, if you also have Report Designer installed, navigate to the Report Designer installation directory, by default (for 64-bit): "C:\Program Files\Windward Studios\AutoTag" or "C:\Program Files\Windward Studios\Windward".
- Delete the WindwardCustomFunctions.dll file, if present.
- Paste your new file in its place.
Set Path to the Custom Functions DLL
Starting In Version 21 also follow these steps
Once you have pasted in the WindwardCustomFunctions.dll file:
- Go to your Designer install location (i.e. C:\Program Files\Windward Studios\Windward)
- If the file AutoTag.dll.config file doesn't exist, create it, otherwise open the file.
- Here is a reference for the structure of the config file: https://ohana.windwardstudios.com/m/76878/l/976702-report-designer-office-edition-configuration-file-reference
- Under the
<WindwardReports>
section of the config file, add the following line with a full path to your WindwardCustomFunctions.dll file, and save the config file.
<add key="function.files" value="C:\path\to\file\WindwardCustomFunctions.dll"/>